import Taro from '@tarojs/taro'


let kOrderMgrRemindedIds = "kOrderMgrRemindedIds"
class OrderMgr {

    static readonly shared = new OrderMgr()

    // 已经提醒过的订单set
    remindedOrderSet = new Set<string>()
    constructor() {

        let jsonStr = Taro.getStorageSync(kOrderMgrRemindedIds)
        if (jsonStr) {
            let ids = JSON.parse(jsonStr)
            this.remindedOrderSet = new Set<string>(ids) 
        }
    }

    static existRemind = (orderId: string) => {
        return OrderMgr.shared.remindedOrderSet.has(orderId)
    }

    static insertReminded = (orderId: string) => {
        if (OrderMgr.existRemind(orderId)) {
            return
        }

        OrderMgr.shared.remindedOrderSet.add(orderId)

        let jsonStr = JSON.stringify(Array.from(OrderMgr.shared.remindedOrderSet))
        Taro.setStorage({key: kOrderMgrRemindedIds, data: jsonStr})
    }

    static clear = () => {
        Taro.removeStorage({
            key: kOrderMgrRemindedIds
        })
    }
}

export default OrderMgr